
import PageView from '../../../static/sys/js/view/PageView'
import _ from "underscore"

var List = PageView.extend({
  area: "List",

  initialize: function () {

    this.$el.on("click", ".list-ul", this.takeRoom.bind(this));
  },
  didRender: function () {
    this.listUl = this.el.querySelector(".list-ul");
    this.noSearchEl = this.el.querySelector(".nosearch-img-w");
    //render

  },
  onResume: function () {
    window.yyesn.client.setHeader({title:"会议室查询",navColor:"#FD746E"});
    //初始化单页的区域滚动
    R('.mui-scroll-wrapper').scroll({
       indicators: false,
       deceleration: 0.0001
    });
  },
  postRoute: function (options) {
    console.log(options);
    if (options) {
      this.ulArray = options.list || [];
      this.timeData = options.timeData;
      this.renderListEl(options);
    }
  },
  renderListEl: function (options) {
    if (options.list.length > 0) {
      var elHtml = [];
      for (var i = 0; i < options.list.length; i++) {
        var each = options.list[i];
        elHtml.push(`
          <li data-id=`+ each.roomID+`>
            <div>
              <span class="list-title">`+ each.room +`</span>
              <span  class="list-money"><span>￥`+ each.cost.substring(0, each.cost.indexOf("."))+`</span><span class="list-time">/h</span></span>
            </div>
            <div class="list-capacity">
              `+ each.roommum + "人 "+ each.floor+`
            </div>
          </li>
          `);
      }
      this.listUl.innerHTML = elHtml.join("");
      this.noSearchEl.classList.remove("active");
    } else {
      this.listUl.innerHTML = "";
      this.noSearchEl.classList.add("active");
    }

  },
  takeRoom: function (e) {
    var target = e.target;
    for (; target && target !== this.listUl; target = target.parentNode) {
      if (target.tagName == 'LI') {
        var id = target.getAttribute("data-id");
        var curentRoom = _.find(this.ulArray, function (each) {return each.roomID == id});
        curentRoom && this.setRouteParam({curentRoom: curentRoom, timeData: this.timeData}, "Detail");
      }
    }
  }

})





export default List
